if(NOT DEFINED CMAKE_C_COMPILER)
    find_program(CMAKE_C_COMPILER clang)
endif()

if(NOT DEFINED CMAKE_CXX_COMPILER)
    find_program(CMAKE_CXX_COMPILER clang++)
endif()

list(FIND CMAKE_OSX_ARCHITECTURES "arm64" ARM64_INDEX)
list(FIND CMAKE_OSX_ARCHITECTURES "x86_64" X86_64_INDEX)

if(${ARM64_INDEX} GREATER -1 AND ${X86_64_INDEX} EQUAL -1)
    option(ENABLE_NEON "neon optimize default" ON)
    if(ENABLE_NEON)
        add_definitions(-DHAVE_NEON)
    endif()
elseif(${ARM64_INDEX} EQUAL -1 AND ${X86_64_INDEX} GREATER -1)
    option(ENABLE_SSE "sse optimize default" ON)
    option(ENABLE_AVX "avx optimize default" ON)

    if(ENABLE_AVX)
        add_definitions(-DHAVE_AVX)
        add_definitions(-mavx)
        add_definitions(-mavx2)
        add_definitions(-mfma)
    endif()

    if(ENABLE_SSE)
        add_definitions(-DHAVE_SSE)
        add_definitions(-DHAVE_SSE2)
        add_definitions(-DHAVE_SSE3)
        add_definitions(-DHAVE_SSE4_1)
        add_definitions(-DHAVE_SSE4_2)
        add_definitions(-msse4.2)
    endif()
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_CFLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fsanitize=address -O0")
    add_compile_options(-O0)
else()
    add_compile_options(-Ofast)
endif()

add_compile_options(-Werror=return-type)
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-fPIC)    
add_compile_options(-ffast-math)
add_compile_options(-std=c++11)

set(FCV_INSTALL_LIB_NAME lib)
